/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelDirectorioIconos.java
 *
 * Created on 28/12/2009, 09:29:39 AM
 */

package org.constant.gui;

import java.awt.GridLayout;
import java.io.File;
import java.util.List;

/**
 *
 * @author gsierra
 */
public class PanelDirectorioIconos extends javax.swing.JPanel {
    private List<File> archivos;
    public final int COLUMNAS = 4;
    /** Creates new form PanelDirectorioIconos */
    public PanelDirectorioIconos() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        spIconos = new javax.swing.JScrollPane();
        pIconos = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        tfTotalArchivos = new javax.swing.JTextField();

        pIconos.setLayout(new java.awt.GridLayout(1, 4));
        spIconos.setViewportView(pIconos);

        jLabel1.setText("Total Archivos");

        tfTotalArchivos.setEditable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(spIconos, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfTotalArchivos, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(spIconos, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfTotalArchivos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
    }// </editor-fold>//GEN-END:initComponents

    public void actualizaInformacion(List<File> archivos){
        this.archivos = archivos;
        this.tfTotalArchivos.setText(Integer.toString(archivos.size()));
        actualizaContenido();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel pIconos;
    private javax.swing.JScrollPane spIconos;
    private javax.swing.JTextField tfTotalArchivos;
    // End of variables declaration//GEN-END:variables

    private void actualizaContenido() {
        GridLayout gl = (GridLayout) pIconos.getLayout();
        pIconos.removeAll();
        pIconos.setLayout(gl);
        gl.setRows(archivos.size() / COLUMNAS);
        for(File archivo: archivos){
            this.pIconos.add(new PanelArchivo(archivo));
        }
    }

}
